<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>必须拿起的最小连续卡牌数</title>
</head>
<body>
  <script>
    function fn(cards) {
      let ret = Infinity;
      let map = {};
      for (let i = 0; i < cards.length; i++) {
        // void 运算符对给定的表达式进行求值
        if (map[cards[i]] !== void 0) {
          ret = Math.min(ret, i - map[cards[i]] + 1);
        }
        map[cards[i]] = i;
      }
      return ret == Infinity ? -1 : ret;
    }
    console.log(fn([3, 4, 2, 3, 4, 7]))
  </script>
</body>
</html>